package com.lh.pospi.x_store.utils;

import com.lh.pospi.x_store.modle.GoodsBean;
import com.vondear.rxtool.RxLogTool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DBService {
    private Connection conn=null; //打开数据库对象
    private PreparedStatement ps=null;//操作整合sql语句的对象
    private ResultSet rs=null;//查询结果的集合
    //DBService 对象
    public static DBService dbService=null;

    /**
     * 构造方法 私有化
     * */

    private DBService(){

    }

    /**
     * 获取MySQL数据库单例类对象
     * */

    public static DBService getDbService(){
        if(dbService==null){
            dbService=new DBService();
        }
        return dbService;
    }

    /**
     * 拉取商品信息
     */
    public void saveGoods() {
        List<GoodsBean> beans = new ArrayList<>();
        String sql = "select item_no as code,item_subno as barcode," +
                "item_name as name,unit_no as unit," +
                "item_size as spec, " +
                "item_supcust as sup,item_clsno as cat," +
                "item_brand as brand,base_price jj,sale_price lsj," +
                "sale_price as pfj,1 jhl,unit_no as junit," +
                "item_rem as memo from t_bd_item_info where status = '1'";
        conn = DBOpenHelper.getConn();
        try {
            if(conn!=null&&(!conn.isClosed())){
                ps= (PreparedStatement) conn.prepareStatement(sql);
                if(ps!=null){
                    rs= ps.executeQuery();
                    if(rs!=null){
                        while(rs.next()){
//                            RxLogTool.w(rs.getString("name")+"--------"+rs.getString("code"));
                            GoodsBean u=new GoodsBean();
                            u.setCode(rs.getString("code"));
                            u.setNum(1);
                            u.setBarcode("barcode");
                            u.setName("name");
                            u.setUnit("unit");
                            u.setSpec("spec");
                            u.setSup("sup");
                            u.setCat("cat");
                            u.setBrand("brand");
                            u.setJj("jj");
                            u.setLsj("lsj");
                            u.setPfj("pfj");
                            beans.add(u);
                        }
                    }
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (beans.size() > 0) {

        }
        DBOpenHelper.closeAll(conn,ps,rs);//关闭相关操作
    }
}
